<template>
  <div class="newsinfo-container">
    <!-- 大标题 -->
    <h1 class="title">{{ newsInfo.title }}</h1>
    <!-- 子标题 -->
    <p class="newsinfo-nav">
      <span>发表时间：{{ newsInfo.add_time }}</span>
      <span>点击：{{newsInfo.count}}次</span>
    </p>
    <hr>
    <!-- 内容区域 -->
    <div class="content" v-html="newsInfo.content">
    </div>
  </div>
</template>

<script>
import {HTTPGetNewDetailById} from "@/api/news.js"
export default {
  data () {
    return {
      newsInfo: {},
      id: this.$route.params.id
    }
  },
  created () {
    // 调用方法
    this.getNewsInfo()
  },
  methods: {
    // 定义方法
    async getNewsInfo () {
      // 获取新闻详情数据
      try {
        let result = await HTTPGetNewDetailById({ id: this.id });
        if (result.code === 1) {
          this.newsInfo = result.data;    
          //console.log(this.newsInfo);       
        }
        else{
          throw result.msg;
        }
      } catch (error) {
        this.$messagebox("错误",error)
      }      
    },//=======================================

     
  }
}
</script>

<style lang="scss">
.newsinfo-container {
  padding: 0 5px;
  .title {
    font-size: 14px;
    text-align: center;
    margin: 10px 0;
    color: orangered;
  }
  .newsinfo-nav {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #26a2ff;
  }
  .content {
    white-space:pre-wrap;
    font-size: 12px;
    img {
      width: 100%;
    }
  }
}
</style>
